<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="expires" content="Thu,01 Jan 1970 00:00:01 GMT">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <!--<meta http-equiv="Content-Security-Policy" content="default-src 'self';font-src 'self' data: https://fonts.gstatic.com https://fonts.googleapis.com/;style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' http://api.map.baidu.com ;">-->
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <link href="__IMG__/logo.png" rel="shortcut icon" type="image/x-icon">
    <title>花椒-辣椒-香料-调味品-附城--成都味之初农产品有限公司</title>
    <base target="_self">
    <meta name="keywords" content="成都调味品批发交易贸易，花椒，辣椒，香料，成都调味品">
    <meta name="description" content="成都味之初农产品有限公司,专注于花椒，辣椒，香料等调味品批发贸易">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="__LIB__/layui/css/layui.css">
    <link rel="stylesheet" href="__CSS__/bootstrap.min.css">
    <link rel="stylesheet" href="__CSS__/reset.css">
    <link rel="stylesheet" href="__CSS__/address.css">
    <link rel="stylesheet" href="__CSS__/common.css">
    <link rel="stylesheet" href="__CSS__/postorder.css">
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?68cca1e88d91513304d45edd3b72a6ba";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>
<body>
    <top class="prod-huajiao">
        <header class="navbar navbar-default">
            <div class="container">
                <!--小屏幕导航按钮和logo-->
                <div class="navbar-header">
                    <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <div id="logo-part-for-mobile" style="display: none;">
                        <a href="http://cdweizhichu.com/">
                            <img src="__IMG__/logo.png" class="logo">
                            <span>附城</span>
                        </a>
                    </div>
                </div>
                <!--小屏幕导航按钮和logo-->
                <!--导航-->

                <div class="navbar-collapse collapse">
                    <div id="logo-part-for-pc">
                        <h1 style="display: inline-block;">
                            <a href="http://cdweizhichu.com/" style="display: block">
                                <img src="__IMG__/logo.png" class="logo">
                                <span class="logo-right-txt">附城</span>
                            </a>
                        </h1>
                    </div>
                    <ul id="main-navigation" class="nav navbar-nav">
                        <li>

                            <a href="/">附城</a>

                        </li>
                        <li >
                            <a href="/index/index/huajiao">花椒</a>
                        </li>
                        <li class="">

                            <a href="/index/index/lajiao">辣椒</a>

                        </li>
                        <li class="">

                            <a href="/index/index/xiangliao">香料</a>

                        </li>
                        <li class="prod-center active">

                            <a href="#">产品中心<i class="nav-arrow-up"></i></a>

                            <ul>
                                <li><a href="/index/index/prodhuajiao" style="background: #CE7D3A;color: #fff;">花椒产品</a></li>
                                <li><a href="/index/index/prodlajiao">辣椒产品</a></li>
                                <li><a href="/index/index/prodxiangliao">香料产品</a></li>
                                <li><a href="/index/index/prodquality">精品展示</a></li>
                            </ul>
                        </li>
                        <li class="">

                            <a href="./news.html">最新资讯</a>

                        </li>
                        <li class="">

                            <a href="./story.html">故事欣赏</a>

                        </li>
                    </ul>
                </div>
                <!--导航-->
            </div>
        </header>
    </top>

    <div class="goods-info-area">
        <div class="title"><span></span><div class="prod_name" style="display: inline-block"></div></div>
        <div class="goods-info">
            <div class="left-pic"><img src="__IMG__/prod-huajiao-sort_001.jpg" alt=""></div>
            <div class="right-info">
                <div class="name">产品名称：<span></span></div>
                <div class="amount">
                    <span>购买数量</span>
                    <span class="count-input-part">
                        <span class="minus">-</span>
                        <span><input type="text" class="count-input" value="1"></span>
                        <span class="add">+</span>
                    </span>
                    <span class="just-goods-price">60.00</span>
                </div>
                <div class="dilivery-way">
                    <span>运送方式：普通配送 快递 免邮</span>
                    <span class="postage">0.00</span>
                </div>
                <div class="divlivery-risk">
                    运费险：卖家送,确认收货前退货可赔 <input type="checkbox" checked disabled>
                    <span class="freight-insurance">0.00</span>
                </div>
            </div>
        </div>
        <div class="goods-bot-info">
            <div class="user-message">
                <span class="message-title">买家留言：</span>
                <textarea type="text" placeholder="选填:填写内容已和卖家协商确认" id="message"></textarea>
                <span class="orderPay">合计(含运费) <span>￥<span class="totalPrice">235.00</span></span></span>
            </div>
            <!--<div class="buy-way">
                <div class="nickname-buy">
                    匿名购买: <input type="checkbox" checked>
                </div>
            </div>-->
            <div class="addr-info_post">
                <div><span>寄送至:</span><span class="info-txt main-area_info"> </span></div>
                <div><span>收货人:</span><span class="info-txt person_info"> </span></div>
                <div><span class="use-new-addr" data-toggle="modal" data-target=".bs-example-modal-lg">使用新地址</span></div>
            </div>
        </div>
        <div class="order-post">
            合计: <span class="priceTxt">¥<span class="g_price">60.00</span></span>
            <span class="post-orderPay">提交订单</span>
            <input type="hidden"  data-toggle="modal" data-target="#myModal" id="post_orderPay">
        </div>
    </div>

    {include file="/common" /}

    <!--user part-->
    {include file="index@base/userinfo"}
    <!--模态框-->
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="addr_Modal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">创建收货地址</h4>
                </div>
                <div class="modal-body">
                    <div class="inner-addr-info">
                        <div class="title">新地址</div>
                        <div class="row-cont row-addr">
                            <span class="item-point addr-info">地址信息:</span>
                            <label for="Addr" id="areaLabel" class="user-fill address">
                                <input type="text" name="Addr" id="Addr" readonly placeholder="请选择省/市/区/街道">
                            </label>
                            <tips class="tips"></tips>
                        </div>
                        <div class="row-cont">
                            <span class="item-point detail-addr">详细地址:</span>
                            <textarea class="user-fill" id="detailAddr" placeholder="请输入详细地址信息，如道路、门牌号、小区、楼栋号、单元等信息"></textarea>
                            <tips class="tips"></tips>
                        </div>
                        <div class="row-cont">
                            <span class="item-point">邮政编码:</span>
                            <span class="user-fill"><input type="text" id="postCode" placeholder="请填写邮编"></span>
                            <tips class="tips"></tips>
                        </div>
                        <div class="row-cont">
                            <span class="item-point consignee">收货人姓名:</span>
                            <span class="user-fill"><input type="text" id="consigneeName" placeholder="长度不超过25个字符" maxlength="25"></span>
                            <tips class="tips"></tips>
                        </div>
                        <div class="row-cont">
                            <span class="item-point consignee-phone">手机号码:</span>
                            <span class="user-fill"><input type="text" id="phone" placeholder="电话号码、手机号码必须填一项"></span>
                            <tips class="tips"></tips>
                        </div>
                        <!--<div class="row-cont">
                            <span class="item-point"></span>
                            <span class="user-fill set-default-addr"><input type="checkbox" id="setDefault"> 设为默认收货地址</span>
                        </div>-->

                        <div class="row-cont btn-save-addr-info">
                            <span class="item-point"></span>
                            <button class="btn btn-primary" id="save">保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--地区模态框-->
    <div id="addressSelectWrapper">
        <div id="addressSelect">
            <div class="tip">
                <h3>所在地区</h3>
                <button type="button" id="cancel"></button>
            </div>
            <div id="address">
                <ul class="selected-address">
                    <li class="lastarea" id="lastprovince">请选择</li>
                    <li class="lastarea" id="lastcity">请选择</li>
                    <li class="lastarea" id="lastarea">请选择</li>
                    <li class="lastarea" id="lasttown">请选择</li>
                </ul>
                <div class="address-content">
                    <ul id="province"></ul>
                    <ul id="city"></ul>
                    <ul id="area"></ul>
                    <ul id="town"></ul>
                </div>
            </div>
        </div>
    </div>
    <!--扫码支付模态框-->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close scanCancel" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="wechat_scan">扫码支付</h4>
                </div>
                <div class="modal-body">
                    <div class="pay-area">
                        <div class="qr_code_box">
                            <div class="info-tips-pay">微信扫码支付</div>
                            <img src="__IMG__/loading.gif" alt="">
                        </div>
                        <div class="qr_inner">
                            <div class="goods-desc">甘肃青花椒</div>
                            <div class="pay-money"><span>¥</span><span class="pay_m_num">239.00</span></div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default scanCancel" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>

    <div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;">
        <div id="innerdiv" style="position:absolute;">
            <img id="bigimg" style="border:5px solid #fff;" src="" />
        </div>
    </div>
</body>
<script src="__JS__/jQuery-1.11.1.min.js"></script>
<script src="__LIB__/layui/layui.js"></script>
<script src="__JS__/bootstrap.min.js"></script>
<script src="__JS__/city.js"></script>
<script src="__JS__/address-check.js"></script>
<script>
    $(function(){
        // 地址选择器遮罩层打开与关闭
        $("#areaLabel").click(function(e){
            $("#addressSelectWrapper").show();
            e.stopPropagation();
        });
        $(document).click(function () {
            $("#addressSelectWrapper").hide();
        });
        $("#cancel").click(function () {
            $("#addressSelectWrapper").hide();
        });
        $("#addressSelect").click(function (e) {
            e.stopPropagation();
        });

        initAddress();
    });

    //初始化地址选择
    function initAddress() {
        $("#Addr").cityLinkage({
            containerId: 'addressSelectWrapper',
            getSelectedCode:function(){return $("#Addr").data("code");},
            callback:function(data) {
                $("#Addr").val(data.addr).data("code",data.town.code);
            }
        });
    }
</script>
<script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>
<script>
    $(function () {
        $('.user-fixed-right').mouseenter(function () {
            $(this).css({right:0,height:'200px',background:'#3A394D',borderColor: '#333',borderRadius:0,transition:'all .3s ease-out'})
            $('.user-edit').show()
        }).mouseleave(function () {
            $(this).css({right:'-50px',height:'100px',background:'#fff',borderColor: '#efa123',borderRadius:'50%',transition:'all .3s ease-out'})
            $('.user-edit').hide()
        })
    })
</script>
<script>
    $(function () {
        layui.use('layer',function () {
            var layer = layui.layer
        })

        var orderNum //订单号
        var good_s_price
//        var good_id = window.location.href.split('good_id=')[1]
        var g_info = JSON.parse(sessionStorage.getItem('good_info'))
        $('.count-input').val(g_info.good_count)
        good_s_price = g_info.good_s_price
        $('.right-info .name span').html(g_info.good_name)
        $('.prod_name').html(g_info.good_name)

        $('.just-goods-price').html(changeTwoDecimal_f(g_info.good_count * g_info.good_s_price))
        $('.totalPrice').html(changeTwoDecimal_f(g_info.good_count * g_info.good_s_price))
        $('.g_price').html(changeTwoDecimal_f(g_info.good_count * g_info.good_s_price))

        /*数量输入、加减*/
        $('.minus,.add').on('click',function () {
            var count = $(this).siblings().find('.count-input').val()
            var inventory = JSON.parse(sessionStorage.getItem('inventorytoMax'))
            var handle = $(this).text()
            if(handle === '-') count--
            if(handle === '+') count++
            if(count > inventory.inventory) count = inventory.inventory
            if(count < 1) count = 1

            $(this).siblings().find('.count-input').val(count)
            $('.just-goods-price').html(changeTwoDecimal_f(count * good_s_price))
            $('.totalPrice').html(changeTwoDecimal_f(count * good_s_price))
            $('.g_price').html(changeTwoDecimal_f(count * good_s_price))
        })



        //限制商品数量字符输入
        var reg = /[^0-9]/g
        $('.count-input').on('keydown',function (ev) {
            $(this).val($(this).val().replace(reg,''))  //避免按住某个非数字键不放，持续输入
        }).on('keyup',function (ev) {
            $(this).val($(this).val().replace(reg,''))  //避免按住某个非数字键不放，持续输入
            if($(this).val().substr(0,1) === '0') {
                $(this).val(1)
            }
        })

        //商品数量至少为1
        $('.count-input').on('blur',function(){
            if(!$(this).val()) {
                $(this).val(1)
            }else {
                $(this).val($(this).val().replace(reg,''))
                if(!$(this).val()) {
                    $(this).val(1)
                }
                var inventory = JSON.parse(sessionStorage.getItem('inventorytoMax'))
                if($(this).val() > inventory.inventory) {
                    $(this).val(inventory.inventory)
                    layer.open({
                        title:'商品信息',
                        content: `此商品最大库存为${inventory.inventory}`
                    })
                }
            }
            var count = $('.count-input').val()
            $('.just-goods-price').html(changeTwoDecimal_f(count * good_s_price))
            $('.totalPrice').html(changeTwoDecimal_f(count * good_s_price))
            $('.g_price').html(changeTwoDecimal_f(count * good_s_price))
        })


        $('#message').on('focus',function () {
            $(this).css({height:'57px',border:'1px solid #ff0036'})
        }).on('blur',function () {
            $(this).css({height:'18px',border:'1px solid #ccc'})
        })

        $.get('/index/member/getMemberAddress',function (res) {
            if(res.code == 1) {
                if(!res.msg.memb_addrPhone) {
                    $('.use-new-addr').click()
                    return
                }
                $('.main-area_info').html(res.msg.memb_city+' '+res.msg.memb_address)
                $('.person_info').html(res.msg.memb_addrName+' '+res.msg.memb_addrPhone)
            }
        },'json')

        /*保存修改地址*/
        $('#save').on('click',function () {

            checkAll()

            var count = 0
            $('.tips').each(function (i,v) {
                if(v.innerText) count++
            })
            if(count > 0) return

            var cons_area = $('#Addr').val().split('/ ')
            cons_area[3] = cons_area[3] ? cons_area[3] : ''
            cons_area = cons_area[0]+cons_area[1]+cons_area[2]+cons_area[3]
            $.post('/index/member/editAddress',{
                memb_city : cons_area,
                memb_address : $('#detailAddr').val(),
                memb_zipCode : $('#postCode').val(),
                memb_addrName : $('#consigneeName').val(),
                memb_addrPhone : $('#phone').val(),
                // cons_default: $('#setDefault')[0].checked //设为默认收货地址
            },function (res) {
                if(res.code === 1) {
                    $('.main-area_info').html(cons_area+' '+$('#detailAddr').val())
                    $('.person_info').html($('#consigneeName').val()+' '+$('#phone').val())
                    layer.msg('添加成功！',{icon:1,time: 2000})
                    setTimeout(function () {
                        $('.close').click()
                    },2000)
                }
            },'json')
        })

        /*提交订单*/
        $('.post-orderPay').on('click',function () {
            $('.qr_code_box img').css({width: '24px'})
            $('.qr_code_box img')[0].src = '__IMG__/loading.gif'


            $('.goods-desc').html(g_info.good_name)
            $('.pay_m_num').html($('.g_price').html())
//            $('#post_orderPay').click()

            orderNum = createOrderNum()

            //describe商品名称 orderNum订单号 id商品id num数量
            if (navigator.userAgent.indexOf('MicroMessenger') != -1 && navigator.userAgent.indexOf('Mobile') != -1) {
                $('#myModal').hide()
                $.post('/index/Wxpay/h5',{
                    describe: '附城产品',
                    orderNum: orderNum,
//                    id: good_id,
                    num: $('.count-input').val()
                },function (res) {
                    if(res) {
                        if(typeof WeixinJSBridge == "undefined"){
                            if( document.addEventListener ){
                                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                            }else if (document.attachEvent){
                                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                            }
                        }else {
                            onBridgeReady(res);
                        }
                    }else {
                        layer.open({
                            title: '商品信息',
                            content: '库存不足，请重新购买'
                        })
                    }

                },'json')

                return
            }else {
                $('#post_orderPay').click()

                $.post('/index/wxpay/scanCode',{
                    describe: '附城产品',
                    orderNum:  orderNum,
                    // id: good_id,
                    goods_Num: $('.count-input').val()
                },function (res) {
                    if(res.code == 200) {
                        $('.qr_code_box img').css({width: '100%'})
                        $('.qr_code_box img')[0].src = res.data
                        queryPayStatus(orderNum)
                    }else {
                        layer.open({
                            title:'提示信息',
                            content: '库存不足'
                        })
                    }
                })
            }
        })

        // 定时器调用判断是否支付
        function queryPayStatus(orderNum) {
                var payInterval = setInterval(function () {
                    $.post("/index/Wxpay/query", {
                        orderNum: orderNum
                    }, function (res) {
                        // 支付判断
                        if(res.trade_state=='SUCCESS'){
                            clearInterval(payInterval);
                            layer.msg('付款成功',{icon:1,time: 2000})
                            $.post("/index/order/createOrder", {
//                                id : good_id,
                                code: "{$code}",
                                orde_num : $('.count-input').val(),
                                orde_NO: orderNum,
                                orde_remark: $('#message').val()
                            }, function (resStatus) {
                                if(resStatus.code === 1) {
                                    setTimeout(function () {
                                        window.location.href = '/index/order/order.html'
                                    },2000)
                                }
                            },'json')
                        }
                    },'json')
                }, 1500)
            //主动取消关闭
            $('.scanCancel').on('click',function () {
                clearInterval(payInterval);
            })
        }

        //保留两位小数
        function changeTwoDecimal_f(x) {
            var f_x = parseFloat(x);
            if (isNaN(f_x)) {
                alert('function:changeTwoDecimal->parameter error');
                return false;
            }
            var f_x = Math.round(x * 100) / 100; //保证小数位不大于2位
            var s_x = f_x.toString();
            var pos_decimal = s_x.indexOf('.');
            if (pos_decimal < 0) {
                pos_decimal = s_x.length;
                s_x += '.';
            }
            while (s_x.length <= pos_decimal + 2) {
                s_x += '0';
            }
            return s_x;
        }

        //生成随机数
        function randomNum(n) {
            var randomNum = ''
            for(var i=0;i<n;i++){
                randomNum += Math.floor(Math.random()*10)
            }
            return randomNum
        }

        //创建订单号
        function createOrderNum() {
            var t = new Date(),
                y = t.getFullYear(),
                mon = t.getMonth() + 1,
                d = t.getDate(),
                h = t.getHours(),
                min = t.getMinutes(),
                s = t.getSeconds()

            if(mon<10) mon = '0'+mon
            if(d<10) d = '0'+d
            if(h<10) h = '0'+h
            if(min<10) min = '0'+min
            if(s<10) s = '0'+s

            orderNum = String(y)+String(mon)+String(d)+String(h)+String(min)+String(s)+randomNum(4)
            return orderNum
        }

        //微信环境下
        function onBridgeReady(paramNeed){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', paramNeed,
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ){
                        // 使用以上方式判断前端返回,微信团队郑重提示：
                        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                        $.post("/index/order/createOrder", {
                            code: "{$code}",
                            orde_num : $('.count-input').val(),
                            orde_NO: orderNum,
                            orde_remark: $('#message').val()
                        }, function (resStatus) {
                            if(resStatus.code === 1) {
                                window.location.href = '/index/order/order.html'
                            }
                        },'json')
                    }
                });
        }




        if(window.screen.width < 500) {
            var prodUl = true
            $('.prod-center>a').on('click',function () {
                if(prodUl) {
                    $(this).siblings().show()
                    $(this).find('.nav-arrow-up').css({transform:'translateY(-20%) rotate(315deg)',transition:'all .35s ease-in-out'})
                    prodUl = false
                }else {
                    $(this).siblings().hide()
                    $(this).find('.nav-arrow-up').css({transform:'translateY(-50%) rotate(135deg)'})
                    prodUl = true
                }
            })
            setTimeout(function () {
                $('.navbar-collapse').children('#logo-part-for-pc').remove()
                $('.collapse').css({height:0,overflow:'hidden',border:'none'}).show()
                $('#logo-part-for-mobile').show()
            }, 800)
        }else{
            setTimeout(function () {

            },800)
        }


        //手机屏下的导航显示
        var toggleState = true
        $('.navbar-toggle').on('click',function () {
            if(toggleState){
                $('.navbar-collapse').css({transform:'scaleY(1)',transformOrigin:'top',transition: 'all .35s ease'})
                if($('.prod-center ul').css('display') === 'block') {
                    setTimeout(function () {
                        $('.navbar-collapse').css({height:'350px'})
                    }, 380)
                }
                toggleState = false
            }else{
                $('.navbar-collapse').css({transform:'scaleY(0)',transformOrigin:'top',transition: 'all .35s ease'})
                if($('.prod-center ul').css('display') === 'block') $('.prod-center ul').css('display') === 'none'
                toggleState = true
            }
        })
        $('.prod-center').on('click',function () {
            if($('.prod-center ul').css('display') === 'block') $('.navbar-collapse').css({height:'350px'})
            else $('.navbar-collapse').css({height:'302px'})
        })

    })
</script>
</html>